package com.loong.game2048.dao;


import com.loong.game2048.module.User;
import org.apache.ibatis.annotations.*;

/**
 * @author lyx
 * @date 2020/5/8 22:28
 */
@Mapper
public interface UserDao {


    /**
     * 新增用户
     * @param openId
     * @return
     */
    @Insert("insert into user(open_id) values(#{openId}) ")
    Integer addUser(@Param("openId") String openId);

    /**
     * 获得用户数，用于判断用户是否存在
     * @param openId
     * @return
     */
    @Select("select count(open_id) from user where open_id = #{openId}")
    Integer getCountById(String openId);

    /**
     * 获得用户所有信息
     * @param openId
     * @return
     */
    @Select("select * from user where open_id = #{openId}")
    @Results(id = "user",value = {
            @Result(property = "openId",column = "open_id"),
            @Result(property = "nickname",column = "nickname"),
            @Result(property = "photo",column = "photo"),
            @Result(property = "background",column = "background")
    })
    User getUserById(String openId);

    /***
     * 修改用户信息
     * @param user
     * @return
     */
    @Update("update user set nickname = #{nickname},photo = #{photo} where open_id = #{openId}")
    @ResultMap("user")
    Integer updateUserMsg(User user);

    /**
     * 修改用户背景图片
     * @param user
     * @return
     */
    @Update("update user set background = #{background} where open_id = #{openId}")
    @ResultMap("user")
    Integer updateUserBackground(User user);

    /**
     * 获得用户昵称和头像
     * @param openId
     * @return
     */
    @Select("select nickname,photo from user where open_id = #{openId}")
    @ResultMap("user")
    User getUserMsgById(String openId);

}
